
function addMerchant(){
    var index = layer.open({
        type: 2,
        title:"添加供应商",
        scrollbar: false,
        content: path+"/manager_merchant/to_add_merchant",
        area: ['900px','600px']
    });
}
function lookMerchant(id){
    var index = layer.open({
        type: 2,
        title:"查看供应商",
        scrollbar: false,
        content: path+"/manager_merchant/look_merchant?id="+id,
        area: ['900px','600px']
    });
}
function editMerchant(id){
    var index = layer.open({
        type: 2,
        title:"编辑供应商",
        scrollbar: false,
        content: path+"/manager_merchant/to_edit_merchant?id="+id,
        area: ['900px','600px']
    });
}
function deleteMerchant(id){
	 layer.confirm("确定删除？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/manager_merchant/delete_merchant",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'id':id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
					    if(data == "success"){
						    layer.msg('删除成功!',{icon:1,time:1000},function(){
						    	$("#search_form").submit();
						    });
					   } else if(data == "fail") {
						layer.alert("操作失败！");
					   } else {
						   layer.alert(data);
					   }
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}
function startMerchant(id){
	 layer.confirm("确定启动此供应商？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/manager_merchant/start_merchant",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'id':id},
					error : function() {
						layer.alert("操作失败");
			        },
					success : function(data) {
					    if(data == "success"){
						    layer.msg('启动成功!',{icon:1,time:1000},function(){
						    	$("#search_form").submit();
						    });
					   }else if(data == "fail"){
						layer.alert("操作失败！");
					   } else {
						   layer.alert(data);
					   }
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}
function stopMerchant(id){
	 layer.confirm("确定禁用此供应商？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/manager_merchant/stop_merchant",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'id':id},
					error : function() {
						layer.alert("操作失败");
			       },
					success : function(data) {
					    if(data == "success"){
						    layer.msg('禁用成功!',{icon:1,time:1000},function(){
						    	$("#search_form").submit();
						    });
					   }else if(data == "fail"){
						layer.alert("操作失败！");
					   } else {
						   layer.alert(data);
					   }
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}
function resetMerchant(id){
	 layer.confirm("确定重设密码？密码将重设为随机数",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/manager_merchant/reset_pas",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{'id':id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
			            var dataArr = data.split(",");
			            if(dataArr[0] == "success"){
			            	layer.alert("重设成功,新的密码为：<b>" + dataArr[1] + "</b>，请妥善保管好新密码");
			            }else{
							layer.alert(data);
						}
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}